<?php if($this->canShowBlock()): ?>
<div class="block block-layered-nav">
    <div class="sidebar-search clearfix">

            <?php echo $this->getStateHtml() ?>
                
            <?php if($this->canShowOptions()): ?>
                    
                    <?php foreach ($this->getFilters() as $_filter): ?>
                        
                        <?php if($_filter->getName() == "Category" && $_filter->getItemsCount()==0): ?>
                                <div class="search-by-category">
                                    <div class="lblhead border-t-l-r"><h3><?php echo $this->__("Search Category") ?></h3></div>
                                        <div class="content-category">
                                            <div class="jcrollbar">
                                               <?php
                                                    $categoryList = Mage::getModel('catalog/category')
                                                        ->getCollection()
                                                        ->addAttributeToSelect('*')
                                                        ->addIsActiveFilter()
                                                        ->addLevelFilter(2)
                                                 ?>
                                                <?php if(count($categoryList) > 1): ?>
                                                    <ul>
                                                        <?php foreach ($categoryList as $_cate): ?>
                                                        <?php if($_cate->getId() != ROOT_CATEGORY): ?>
                                                            
                                                            <?php $productCollection = $_cate->getProductCollection()
                                                                                    ->joinField(
                                                                                    'qty',
                                                                                    'cataloginventory/stock_item',
                                                                                    'qty',
                                                                                    'product_id=entity_id',
                                                                                    '{{table}}.stock_id=1',
                                                                                    'left'
                                                                                )
                                                                                ->addAttributeToFilter('qty', array('gt' => 0)); ?>
                                                            <?php $_item_count = count($productCollection);?>
                                                            <?php $cateId = $_cate->getId();?>
                                                            <?php if($_item_count > 0): ?>
                                                                <li>
                                                                    <a href="<?php echo $this->getUrl("catalogsearch/result")."?cat=$cateId&q=1"?>">
                                                                        <label><?php echo $_cate->getName()." ($_item_count)" ?></label>
                                                                    </a>
                                                                </li>
                                                            <?php endif; ?>
                                                        <?php endif ?>
                                                        <?php endforeach ?>
                                                    </ul>
                                                <?php endif ?>
                                            </div>
                                        </div>
                                </div>
                        <?php endif; ?>
                    <?php endforeach; ?>
                    <?php foreach ($this->getFilters() as $_filter): ?>
                        <?php $attribute = $_filter->getAttributeModel(); ?>

                        <?php $code = ""; ?>
                        <?php if(!empty($attribute)): ?>
                            <?php $code = $attribute->getAttributeCode();  ?>
                        <?php endif;?>
                    
                    <?php if($_filter->getItemsCount() ):?>
                        
                        <?php if($_filter->getName() == "Category"): ?>
                            
                            <div class="search-by-category">
                                <div class="lblhead border-t-l-r"><h3><?php echo $this->__("Search Category") ?></h3></div>
                                <?php echo $_filter->getHtml() ?>
                            </div>
                        <?php elseif($code == "manufacturer"): ?>            
                                <div class="search-by-category mar5">
                                    <div class="lblhead border-t-l-r">
                                        <h3><?php echo $this->__("Search Make") ?></h3>
                                    </div>
                                    <div class="content-category">
                                        <div class="jcrollbar">
                                            <?php echo $_filter->getHtml() ?>
                                        </div>
                                    </div>
                                </div>

                        <?php else:?>
                            <div class="rand-price border-t-l-r">
                                <?php echo $_filter->getHtml() ?>
                            </div>
                            
                        <?php endif; ?>
                    <?php endif; ?>
                    <?php endforeach; ?>
                        
                        <div class="search-by-category mar5">
                            
                                <div class="lblhead border-t-l-r">
                                    <h3><?php echo $this->__("Search Unit") ?></h3>
                                </div>
                                <div class="content-category2">
                                    <div class="item first">
                                        <label> <?php echo $this->__("NBS Part #") ?></label>
                                        <input type="text" name="sku" id="sku"/>
                                        <a class="btn-update" id="sku_search" href="javascript:void(0)" ><?php echo $this->__("Search") ?></a>
                                    </div>
                                    <div class="item">
                                        <label> <?php echo $this->__("Model #") ?></label>
                                        <input  type="text" name="model" id="model" />
                                        <a class="btn-update" id="model_search" href="javascript:void(0)"><?php echo $this->__("Search") ?></a>
                                    </div>
                                    <div class="item">
                                        <label> <?php echo $this->__("OEM #") ?></label>
                                        <input  type="text" id="oem"/>
                                        <a class="btn-update" href="javascript:void(0)" id="oem_search"><?php echo $this->__("Search") ?></a>
                                    </div>
                                </div>
                        </div>            
                        
                       
            <?php endif; ?>
    </div>
<input type="hidden" id="url_home" value="<?php echo $this->getUrl("home/index/search")?>" />
 <script type="text/javascript">

    jQuery(document).ready(function(){

        jQuery('.jcrollbar').jScrollPane();
        var url =  jQuery("#url_home").val();
        jQuery("a#sku_search").unbind("click").bind("click",function(){
            jQuery(".amshopby-overlay").remove();
            if(jQuery("#sku").val()==""){
                alert("please input NBS Part #");    
                return;
            }
            
            url = url + "?sku=" + jQuery("#sku").val();
            window.location = url;
        });
        jQuery("a#model_search").unbind("click").bind("click",function(){

            jQuery(".amshopby-overlay").remove();
            if(jQuery("#model").val()==""){
                alert("please input Model #");   
                return;
            }
            
            url = url + "?model=" + jQuery("#model").val();
            window.location = url;
       });
        jQuery("a#oem_search").unbind("click").bind("click",function(){

            jQuery(".amshopby-overlay").remove();
            if(jQuery("#oem").val()==""){
                alert("please input OEM #");
                return;
            }
            
            url = url + "?oem=" + jQuery("#oem").val();
            window.location = url;
       });

    });

</script>


</div>
<?php else: ?>
<div style="display:none" class="<?php echo $this->getBlockId()?>"></div>
<?php endif; ?>

